package medicine.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import medicine.service.MedicineService;
import medicine.service.MedicineRecordVO;

import java.sql.Date;
/**
 * Created by qianyang on 2018/5/2.
 */
@RestController
@RequestMapping(value = "/api/Medicine")
public class MedicineController {

    @Autowired
    private MedicineService medicineService;

    //显示某用户、某一天的药物记录
    @RequestMapping(value = "/records", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String selectMedicineRecord(Integer userId,Date date) {
        return medicineService.selectMedicineRecord(userId,date);
    }

    //添加药物记录
    @RequestMapping(value = "/records", method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String insertMedicineRecord(@RequestBody MedicineRecordVO medicineRecordVO){
        System.out.println("controller");
        return medicineService.insertMedicineRecord(medicineRecordVO);
    }

    //删除药物记录
    @RequestMapping(value = "/records", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delectMedicineRecord(Integer id){
        return medicineService.delectMedicineRecord(id);
    }

    //更新药物记录
    @RequestMapping(value = "/recordsUpdate", method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateMedicineRecord(@RequestBody MedicineRecordVO medicineRecordVO){
        System.out.println("controller");
        return medicineService.updateMedicineRecord(medicineRecordVO);
    }

    @RequestMapping(value = "/record", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String selcetMedicineRecordById(Integer medicineRecordId){
        System.out.println("controller");
        return medicineService.selcetMedicineRecordById(medicineRecordId);
    }

    //显示某id对应的药物信息
    @RequestMapping(value = "/medicine", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String selcetMedicineById(Integer medicineId) {
        return medicineService.selcetMedicineById(medicineId);
    }

    //显示运动列表
    @RequestMapping(value = "/medicineList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String selcetALLMedicine() {
        return medicineService.selcetALLMedicine();
    }

    //搜索药物
    @RequestMapping(value = "/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String searchMedicineByNmae(String name) {
        System.out.println("in controller");
        return medicineService.searchMedicineByNmae(name);
    }

}

